package sixlevel;


/**
 * @Auther: Lee
 * @Date: 2018/7/19 11:54
 * @Description: 设计一个方法 需要传入三个参数a ,b ,c ，a为数组值得差值，b,c为一个范围，
 * 要求返回，b,c范围内的差值为a的质数组合（只能被1和自己整除的数）
 * step(2, 5, 7) --> [5, 7] or (5, 7) or {5, 7} or "5 7".
 * step(2, 5, 5) --> nil or ... or [] in Ocaml or {0, 0} in C++
 * step(4, 130, 200) --> [163, 167] or (163, 167) or {163, 167}
 * 自己写的运行超时了 我累个去
 */
public class StepsinPrimes {


    public static void main(String[] args) {
//        long[] num = getNum(2, 100, 110);
//        long[] check = check(100, 110);
//        for (long a : num) {
//            System.out.println(a);
//        }
//        System.out.println(System.currentTimeMillis());


    }


    public static long[] getNum(int g, long m, long n) {
        long[] result = new long[2];
        long[] check = check(m, n);

        if (check == null) {
            return null;
        }
        int count = 0;
        for (int i = 0; i < check.length - 1; i++) {
            if (count == 1) {
                break;
            }
            long temp = check[i];
            for (int a = 1; a < check.length; a++) {
                long secTemp = check[a];
                if (temp + g == secTemp && count == 0) {
                    result[0] = temp;
                    result[1] = secTemp;
                    count++;
                    break;
                }
            }
        }
        return result;
    }


    /**
     * 得到范围内的质数
     *
     * @param a
     * @param b
     * @return
     */
    public static long[] check(long a, long b) {
        long[] data = new long[(int) b];
        int e = 0;
        Boolean flag = true;
        if (b < a || a == b) {
            return null;
        }
        for (; a <= b; a++) {
            if (a == 1 || a == 2 || a == 3) {
                data[e] = a;
                e++;
            } else {
                for (int i = 2; i < a; i++) {
                    if (a % i == 0) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    data[e] = a;
                    e++;
                }
                flag = true;
            }
        }
        return data;
    }

}
